package oj;

import java.util.ArrayDeque;
import java.util.Deque;

public class LC456 {
    public boolean find132pattern(int[] nums) {
        int k=Integer.MIN_VALUE;
        Deque<Integer> d=new ArrayDeque<>();
        for(int i=nums.length-1;i>=0;i--){
            if(nums[i]<k){
                return true;
            }
            while(!d.isEmpty() && nums[i]>d.peek()){
                k=Math.max(k,d.pop());
            }
            d.push(nums[i]);
        }
        return false;
    }
}
